import { NextResponse } from "next/server"

/**
 * 获取用户创建的歌单
 *
 * @route GET /api/user/playlists
 * @param {number} page - 页码，默认为1
 * @param {number} limit - 每页数量，默认为20
 *
 * @returns {Object} 返回用户创建的歌单列表
 *
 * 请求示例:
 * GET /api/user/playlists?page=1&limit=20
 * Authorization: Bearer <token>
 *
 * 返回示例:
 * {
 *   "success": true,
 *   "data": [
 *     {
 *       "id": "1",
 *       "name": "我喜欢的音乐",
 *       "cover": "/images/playlist-cover.jpg",
 *       "songCount": 42,
 *       "createdAt": "2023-06-01T12:00:00Z",
 *       "isPublic": true
 *     },
 *     // ... 更多歌单
 *   ],
 *   "pagination": {
 *     "currentPage": 1,
 *     "totalPages": 5,
 *     "totalItems": 100
 *   }
 * }
 */
export async function GET(request: Request) {
  const { searchParams } = new URL(request.url)
  const page = Number(searchParams.get("page") || "1")
  const limit = Number(searchParams.get("limit") || "20")

  // 注释让用户使用新的接口
  // This endpoint is for backward compatibility only.
  // Please use /api/user/favorites/playlists for future development

  // 重定向到新的API端点
  return NextResponse.redirect(
    `${process.env.NEXT_PUBLIC_API_BASE_URL || ""}/api/user/favorites/playlists?${searchParams.toString()}`,
  )
}

/**
 * 创建新歌单
 *
 * @route POST /api/user/playlists
 * @param {Object} request.body - 请求体
 * @param {string} request.body.name - 歌单名称
 * @param {boolean} request.body.isPublic - 是否公开，默认为true
 * @param {string} request.body.description - 歌单描述，可选
 *
 * @returns {Object} 返回创建的歌单信息
 *
 * 请求示例:
 * POST /api/user/playlists
 * Content-Type: application/json
 * Authorization: Bearer <token>
 *
 * {
 *   "name": "新歌单",
 *   "isPublic": true,
 *   "description": "这是我的新歌单"
 * }
 *
 * 返回示例:
 * {
 *   "success": true,
 *   "data": {
 *     "id": "123",
 *     "name": "新歌单",
 *     "cover": "/images/default-playlist.jpg",
 *     "songCount": 0,
 *     "createdAt": "2023-06-15T08:30:00Z",
 *     "isPublic": true,
 *     "description": "这是我的新歌单"
 *   }
 * }
 */
export async function POST(request: Request) {
  const body = await request.json()

  // 实现创建歌单逻辑
  return NextResponse.json({
    success: true,
    data: {
      id: "123",
      name: body.name,
      cover: "/images/default-playlist.jpg",
      songCount: 0,
      createdAt: new Date().toISOString(),
      isPublic: body.isPublic,
      description: body.description,
    },
  })
}

